package com.doit.demo04;

import java.io.*;
import java.util.ArrayList;

public class test {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        ArrayList<Person> list = new ArrayList<>();
        list.add(new Person("丹迪",1));
        list.add(new Person("骂米",2));
        list.add(new Person("桑",3));

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("day21\\obj\\list.txt"));
        oos.writeObject(list);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("day21\\obj\\list.txt"));
        Object o = ois.readObject();
        System.out.println(o);
        ArrayList<Person>p= (ArrayList<Person>) o;

        for (Person person : p) {
            System.out.println(person);
        }
        ois.close();
    }
}
